Text View Modifiers
The following properties allow you to style and format text-based views, such as Text or Label, in ways that closely mirror SwiftUI’s built-in modifiers. By customizing these properties, you can control the font, weight, design, spacing, and other typographic attributes of the displayed text.
Overview
These properties are generally passed to text-related views like Text or Label components as attributes. For example, you can specify a font size, enable bold formatting, or add an underline with a custom color—all without manually calling multiple modifiers.
In the example above, the text uses a custom font, semibold weight, italic style, a red underline, limits to two lines, and centers the text.
Font Configuration
font
Defines the font and size to apply to the text.
- Number: When you provide a number (e.g.,
14), it applies the system font at that size. - Preset Font Name (
Fonttype): Use one of the built-in text styles ("largeTitle","title","headline","subheadline","body","callout","footnote","caption"). The system determines the size and weight based on that style. - Object with name and size: Apply a custom font by specifying the
nameandsize.
fontWeight
Sets the thickness of the font’s stroke. Options range from "ultraLight" to "black".
fontWidth
Specifies the width variant of the font if available. Possible values include "compressed", "condensed", "expanded", and "standard". You can also use a numeric value if supported.
fontDesign
Modifies the font design. Options include "default", "monospaced", "rounded", "serif".
Text Formatting
minScaleFactor
A number between 0 and 1 that indicates how much the text can shrink if it doesn’t fit the available space. For example, 0.5 means the text can shrink down to 50% of its original size to fit.
bold
Applies a bold font weight if true.
baselineOffset
Adjusts the text’s vertical position relative to its baseline. Positive values move the text up, negative values move it down.
kerning
Controls the spacing between characters. A positive value increases spacing; a negative value decreases it.
italic
Applies an italic style if true.
monospaced
Forces all child text to use a monospaced variant, if available.
monospacedDigit
Uses fixed-width digits while leaving other characters as they are. This helps align numbers vertically, useful for tables or timers.
Text Decorations
strikethrough
Applies a strikethrough (line through the text). You can provide a color, or an object specifying a pattern and color.
- Color only:
strikethrough="red" - Object:
strikethrough={{ pattern: 'dash', color: 'blue' }}
underline
Applies an underline in a similar way to strikethrough.
- Color only:
underline="blue" - Object:
underline={{ pattern: 'dashDot', color: 'green' }}
Line & Layout Control
lineLimit
Specifies how many lines of text can display. You can provide:
- A single number for a maximum line limit.
- An object
{ min?: number; max: number; reservesSpace?: boolean }to specify a minimum and maximum number of lines, and whether the text should reserve space for all those lines even when not used.
lineSpacing
Sets the spacing between lines, in pixels.
multilineTextAlignment
Sets the text alignment for multi-line text: "leading", "center", or "trailing".
truncationMode
Specifies how to truncate a line of text when it is too long to fit within the available horizontal space.
Type
Description
Defines the position at which the text is truncated:
-
"head": Truncates the beginning of the line, preserving the end. -
"middle": Truncates the middle of the line, preserving both the beginning and end. -
"tail": Truncates the end of the line, preserving the beginning.
allowsTightening?: boolean
Determines whether the system is allowed to reduce the spacing between characters to fit the text within a line when needed.
Type
boolean
Default
false
Description
When set to true, the system may compress the character spacing to avoid truncation and better fit the content. This is typically used to improve layout responsiveness in constrained environments.
Summary
By combining these properties, you can fully control the typography of your text-based views without needing multiple wrapper components or modifiers. Whether you need a bold, italic headline font with custom kerning and underline, or a simple body font that truncates after two lines, these options cover a broad range of text styling needs.
